import { _decorator, Component, game, Node } from 'cc';
import { HttpCom } from './net/HttpCom';
import { Config } from './Config';
import { GameEvent, PropUpType } from './EventName';
const { ccclass, property } = _decorator;

@ccclass('AirDropItem')
export class AirDropItem extends Component {

    public static airDrops: Node[] = [];
    start() {
        AirDropItem.airDrops.push(this.node);
        console.log(AirDropItem.airDrops,"空投");
        if(AirDropItem.airDrops.length >= 2){
            AirDropItem.airDrops[0].destroy();
            AirDropItem.airDrops.splice(0,1);
            console.log(AirDropItem.airDrops);

        }
        this.node.on(Node.EventType.TOUCH_END,this.onTouchend,this);
    }

    onTouchend(){

        HttpCom.post(Config.getRandomDrop,null,(resp)=>{

            console.log(resp);

            this.node.destroy();
            if(resp.data){
                game.emit(GameEvent.SHOW_REWARD_PROPUP,resp,PropUpType.AirDropReward)
            }
        })
        
    }

    update(deltaTime: number) {
        
    }
}


